<template>
  <div>
    <ComDialog
      @EventClose="closeFn"
      title="新增铭感词"
      @
      :dialogVisible="dialogVisible"
    >
      <el-form
        label-width="100px"
        :model="addForm"
        ref="form"
        :rules="addFormRules"
      >
        <el-form-item label="铭感词内容" prop="text">
          <el-input v-model="addForm.text"></el-input>
        </el-form-item>
        <el-form-item prop="level" label="铭感词内容">
          <el-radio-group v-model="addForm.level">
            <el-radio :label="1">一级</el-radio>
            <el-radio :label="2">二级</el-radio>
            <el-radio :label="3">三级</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="铭感词内容">
          <el-button @click="closeFn">取消</el-button>
          <el-button
            type="primary"
            @click="saveFn"
            v-hasPermi="['base:sensitive:add']"
            >保存</el-button
          >
        </el-form-item>
      </el-form>
    </ComDialog>
  </div>
</template>

<script>
import ComDialog from "../../../components/comDialog.vue";
export default {
  components: { ComDialog },
  props: {
    dialogVisible: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      addForm: {
        text: "",
        level: "",
      },
      addFormRules: {
        text: [
          {
            type: "string",
            required: true,
            trigger: "blur",
            message: "不可以为空哦",
          },
        ],
        level: [
          {
            required: true,
            trigger: "change",
            message: "不可以为空哦",
          },
        ],
      },
    };
  },
  methods: {
    closeFn() {
      // 清空
      this.addForm = {
        text: "",
        level: "",
      };
      this.$refs.form.clearValidate();

      this.$emit("update:dialogVisible", false);
    },
    // 保存
    async saveFn() {
      try {
        await this.$refs.form.validate();
        this.$emit("EventgetData", this.addForm);
        this.$refs.form.clearValidate();
      } catch (error) {
        this.$message({
          type: "warning",
          message: error,
        });
      }
    },
  },
};
</script>

<style>
</style>